package cn.com.xy.sms.sdk.ui.popu.part;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import cn.com.xy.sms.sdk.Iservice.XyCallBack;
import cn.com.xy.sms.sdk.smsmessage.BusinessSmsMessage;
import cn.com.xy.sms.sdk.ui.R;
import cn.com.xy.sms.sdk.ui.popu.util.ThemeUtil;
import cn.com.xy.sms.sdk.ui.popu.widget.DuoquProgressBarTable;
import cn.com.xy.sms.sdk.ui.popu.widget.DuoquProgressViewShowMoreInfo;
import cn.com.xy.sms.util.ParseManager;

public class BubbleProgressBarTable extends UIPart {

    private DuoquProgressBarTable mContentListView;
    private LinearLayout mDoubleLayout;
    private static int DEFAULT_SHOW_ROW = 5;
    private static int MAX_SHOW_ROW = 8;
    private static final String TABLE_KEY = "duoqu_table_data_carrier";

    public BubbleProgressBarTable(Activity mContext, BusinessSmsMessage message, XyCallBack callback, int layoutId,
            ViewGroup root, int partId) {
        super(mContext, message, callback, layoutId, root, partId);
    }

    @Override
    public void initUi() {
        mContentListView = (DuoquProgressBarTable) mView.findViewById(R.id.duoqu_progressbar_list);
        mDoubleLayout = (LinearLayout) mView.findViewById(R.id.duoqu_progressbar_layout);
    }

    @Override
    public void setContent(BusinessSmsMessage message, boolean isRebind) throws Exception {
        this.mMessage = message;
        if (message == null) {
            return;
        }

        ThemeUtil.setViewBg(mContext, mView, "", R.drawable.duoqu_v_by_bg_1);
        mContentListView.setDefaultShowRow(DEFAULT_SHOW_ROW, MAX_SHOW_ROW);

        int size = message.getTableDataSize(TABLE_KEY);
        if (size == 0) {
            mView.setVisibility(View.GONE);
        } else {
            mView.setVisibility(View.VISIBLE);
        }
        mContentListView.setContentList(message, size, TABLE_KEY, isRebind);
    }

    /* SMARTISAN-492 zhaoxiachao 20170324 start */
    @Override
    public void destroy() {
        super.destroy();

        try{
            mMessage.bubbleJsonObj.put(DuoquProgressViewShowMoreInfo.KEY_EXPANDED, false);
            ParseManager.updateMatchCacheManager(mMessage);
        }catch(Throwable ex){}
    }
    /* SMARTISAN-492 zhaoxiachao 20170324 end */
}
